package com.stars.empoly.vmodel

import android.app.Application
import android.graphics.Color
import android.text.TextUtils
import android.view.View
import android.widget.LinearLayout
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.hwangjr.rxbus.RxBus
import com.stars.empoly.config.ConfigRx
import com.stars.empoly.inte.ChoiceData
import com.stars.empoly.model.User
import com.stars.empoly.utils.PopuTipsUtils
import com.stars.empoly.utils.net.NetEngine
import com.trailer.base.base.BRRepository
import com.trailer.base.base.BRViewModel
import com.trailer.base.net.IResp
import kotlinx.coroutines.launch

/**
 *
 *on 2020/9/25
 */
class MsgVModel(application: Application) : BRViewModel<BRRepository>(application) {




    var ll: LinearLayout?=null
    var index=MutableLiveData<Int>()

    fun toDelete(id:String?,position:Int?){

        PopuTipsUtils.show(repository().context!!,"确定删除该消息么？",ll!!,object : ChoiceData {
            override fun onRestuse(content: String?) {
                viewModelScope.launch{
                    var it=repository().lreq { NetEngine.service.messageDel(id) }
                    if(it.ok(true)){
                        index.value=position
                    }
                }
            }
        })

    }


    fun toSetRead(){
        viewModelScope.launch {
            var it=repository().lreq { NetEngine.service.messageRead(null,"1") }
            if(it.ok()){
                //刷新列表
                RxBus.get().post(ConfigRx.MSG_RED, "")


            }
        }

    }


    override fun apiFunc(): suspend () -> IResp<*> {
        return { NetEngine.service.msgNewsList(10, repository().page) }
    }



}
